package com.cea.papyrustest.uml.createcommand;

import org.eclipse.uml2.uml.Comment;
import org.eclipse.uml2.uml.Constraint;
import org.eclipse.uml2.uml.Element;

import com.cea.papyrus.core.commands.UMLElementCreateCommand;

/**
 * Test Class for {@link Comment} creation command
 * @author Remi Schnekenburger
 */
public class ConstraintCreateCommandTest extends PapyrusCommandTest {


	protected static String NAME="Constraint0";
	/**
	 * Default constructor
	 * @param name name of the test case
	 */
	public ConstraintCreateCommandTest(String name) {
		super(name);	
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrustest.PapyrusCommandTest#setUp()
	 */
	@Override
	protected void setUp() throws Exception {
		super.setUp();
		papyrusCommand= new UMLElementCreateCommand(org.eclipse.uml2.uml.Constraint.class,model);
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrustest.PapyrusCommandTest#testExecute()
	 */
	@Override
	public void testExecute() {
		stack.execute(papyrusCommand);
		Element clazz=model.getOwnedRule(NAME);
		assertNotNull("the constraint is created",clazz);
		assertTrue("this is not a constraint",((clazz)instanceof Constraint));
		
		stack.undo();
		assertNull("the constraint exist!",model.getOwnedRule(NAME));
		
		stack.redo();
		clazz=model.getOwnedRule(NAME);
		assertNotNull("the constraint is not re-created",clazz);
		assertTrue("this is not a constraint",((clazz)instanceof Constraint));
	}
}
